#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDateTime>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    this->timeProcessing();

    this->eventFilter=new ClickedEventFilter;
    //安装事件过滤器
    ui->label_weather->installEventFilter(this->eventFilter);
    ui->label_music->installEventFilter(this->eventFilter);
    ui->label_video->installEventFilter(this->eventFilter);
    ui->label_map->installEventFilter(this->eventFilter);

    connect(this->eventFilter,&ClickedEventFilter::labelCliched,this,&MainWindow::toWindow);

    this->weather=new WeatherWindow(this);
    this->music=new MusicWindow(this);
    this->video=new VideoWindow(this);
    this->map=new MapWindow(this);
    ui->btn_goon->hide();
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::timeProcessing()
{
    this->showTime();
    this->timer=new QTimer;
    connect(this->timer,&QTimer::timeout,this,&MainWindow::showTime);
    timer->start(1000);
}

void MainWindow::showTime()
{
    //获取当前时间
    QDateTime datetime=QDateTime::currentDateTime();
    QString time=datetime.toString("HH:mm:ss");
    QString date=datetime.toString("yyyy-MM-dd");
    QString week=datetime.toString("ddd");
    ui->label_time->setText(time);
    ui->label_datatime->setText(date);
    ui->label_week->setText(week);
}

void MainWindow::toWindow(QObject *watched)
{
    if(watched->objectName()=="label_weather"){
        this->weather->init();
        this->weather->show();
        this->hide();
    }else if (watched->objectName()=="label_music") {
        this->music->init();
        this->music->show();
        this->hide();
    }else if (watched->objectName()=="label_video") {
        this->video->show();
        this->hide();
    }else if (watched->objectName()=="label_map") {
        this->map->init();
        this->map->show();
        this->hide();
    }
}


void MainWindow::on_btn_timeout_clicked()
{

    ui->btn_goon->setVisible(true);
    ui->btn_timeout->setVisible(false);
}


void MainWindow::on_btn_goon_clicked()
{
    ui->btn_timeout->setVisible(true);
    ui->btn_goon->setVisible(false);
}

